<?php include_once dirname(__FILE__).'/common/header.php'; ?>

<?php include_once dirname(__FILE__).'/common/menu.php'; ?>

var attr = <?php echo json_encode($attr) ?>;
var ctrlName = '<?php echo $ctrlName ?>';

list.baseFrm = function(r){
    var paramsData = r ? {banner_id:r.banner_id}: {};
    var win = new ZM.PopUp({
        title:r ? '编辑banner'  : '新建banner',
        type:'m',
        items:new ZM.FormPanel({
            url:list.baseUrl +  ctrlName + (r ? '/editbanner' : '/createBanner'),
            keySubmit:false,
            fileUpload:true,
            params:paramsData,
            // onlyShow:r ? r.banner_status == 1 : false,
            success:function(res) {
                ZM.bo.msg('success',res.detail);
                list.grid.store.reload();
                win.close();
            },
            items:[{
                fieldLabel:'链接',
                name:'banner_url',
                value:r ? r.banner_url : undefined,
                allowBlank:true
            },{
                xtype:'displayfield',
                fieldLabel:'现有图片',
                value:r ? ZM.cellImage(r.banner_image) : '',
                hidden:r ? false : true
            },{
                inputType:'file',
                fieldLabel:'图片',
                name:'banner_image',
                allowBlank:r ? true : false
            },{
                xtype:'displayfield',
                fieldLabel:'',
                value:'<span class="red">上传图片大小:'+attr.banner_image_width+'x'+attr.banner_image_height+'</span>'
            }]
        })
    }).show();
}


list.statusFrm = function(r,msg,method){
    Ext.Msg.confirm('确认?',msg,function(btn) {
        if(btn != 'no') {
            ZM.ajax({
                url: list.baseUrl +  ctrlName + method,
                params:{banner_id:r.banner_id},
                mask:list.grid,
                success:function(res){
                    ZM.bo.msg('success!',res.detail);
                    list.grid.store.reload();
                }
            });
        }
    });
}


list.grid = new ZM.EditorGridPanel({
    url: list.baseUrl + 'banner/getBannerList',
    tbar:[{
        text:'新建Banner',
        cls:'btn-show',
        hidden:!Ext.permission[ctrlName + '/createBanner'.toLowerCase()],
        iconCls:'icon-create',
        handler:function() {
          list.baseFrm(false);
        }
    }],
    columns:[
        {header:'ID',dataIndex:'banner_id'},
        {header:'图片',dataIndex:'banner_image',width:100,renderer:ZM.cellImage},
        {header:'链接',dataIndex:'banner_url',width:150,renderer:ZM.cellUrl},
        {header:"排序",xtype:'sortcolumn',url: ctrlName + '/editBannerSort',dataId:'banner_id',dataIndex: 'banner_sort'},
        {header:'状态',dataIndex:'banner_status',width:65,renderer:ZM.status,filter:{
            xtype:'combofield',
            options:[['','全部'],['-1','新增'],['0','禁用'],['1','发布']]
        }},
        {header:'最后操作时间',dataIndex:'banner_time_lastmodified',width:140},
        {header:'操作',renderer:function(v,p,r){
            var str = '';
            str += Ext.rd('编辑','fireEdit',r,ctrlName + '/editBanner');
            if(r.json.banner_status == '1') {
                str += Ext.rd('禁用','fireDisable',r,ctrlName + '/disableBanner');
            } else {
                str += Ext.rd('发布','fireActive',r,ctrlName + '/activeBanner');
                str += Ext.rd('删除','fireDelete',r,ctrlName + '/deleteBanner','red');
            }
            return str;
        }}
    ]
});

list.grid.fireEdit = function(r) {
    var r = r.json;
    list.baseFrm(r);
}

list.grid.fireDisable = function(r) {
    var r = r.json;
    list.statusFrm(r,'确定要禁用banner?','/disableBanner');
}

list.grid.fireActive = function(r) {
    var r = r.json;
    list.statusFrm(r,'确定要发布banner?','/activeBanner');
}
list.grid.fireDelete = function(r) {
    var r = r.json;
    list.statusFrm(r,'确定要删除banner?','/deleteBanner');
}



<?php include_once dirname(__FILE__).'/common/layout.php'; ?>
list.grid.store.load();
<?php include_once dirname(__FILE__).'/common/footer.php'; ?>
